package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.pojo.Result;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {
    @Reference
    private OrderSettingService orderSettingService;

    @RequestMapping("/importOrderSettings.do")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file){
        System.out.println("上传的文件是"+file);
        Result result = null;
        try {
            List<String[]> readExcel = POIUtils.readExcel(file);
            result = orderSettingService.importOrderSettings(readExcel);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/findAllByMoth.do")
    public Result findAllByMoth(@RequestParam("year") String year,@RequestParam("month") String month){
        Result result = orderSettingService.findAllByMoth(year,month);
        return result;
    }

    @RequestMapping("/updateOrderSettingByDate.do")
    public Result updateOrderSettingByDate(@RequestParam("updateDate") String updateDate,@RequestParam("number") String number){
        Result result = orderSettingService.updateOrderSettingByDate(updateDate,number);
        return result;
    }
}
